<?php

/**
 * Set active language on a user
 *
 *
 * @package BABEL
 * @since   BABEL 0.1.0
 * @version $Id: set_active_language.php 766 2008-05-14 08:52:59Z bjori $
 * @copyright Copyright (C) 2008 Knut Haug
 * @author  Knut Haug
 * @license LGPL
 */


include('includes/babel/prepend_no_gui.php');


$langid = $_GET['action'];

/*
 * SQL statement which updates and sets the current active language the user 
 * has. Which he then will be able to translate to.
 *
 * 2params:
 * $_SESSION["user"]["user_id"] 	- The user id
 * $langid 							- THe language id to remove
 */
$DB_QUERY = "
			UPDATE
				babel_users
			SET
				language_id = ?
			WHERE
				user_id = ? 
			";

/*
 * Executes the query, and throws a new Exception if it fails.
 *
 * 1param:
 * String - The error message to be shown
 */
if (!PDODB::execQuery($DB_QUERY, array($_GET['action'], $_SESSION['user']['user_id']))) {
	throw new Exception("Invalid DB query");
}

$_SESSION['user']['profile']['active_language'] = $_GET['action'];

